exports.MMSettingsWindow = GL2.Node.subclass(
{
    classname: 'MMSettingsWindow',
    
    initialize: function() 
    {
		this._backgroundImage = null;
		this._closeButton = null;
		this._menuTopLabel = null;
		this._webView = null;
		this._sendFeedbackButton = null;
		this._creditsButton = null;
		this._soundButton = null;
		this._effectsButton = null;
		//GALocalizationHandler.getRelativeString(Core.Localization.getString("TZ_MESSAGE_OFFERS_COINS_BUCKS"),[totalCoinsDiff,totalBucksDiff]);
    },
	
	createView: function() 
	{
		this.makeTouchSwallower();
		
		var backgroundImagePath = this.getBaseResourcePath() + "main-menu-background.png";
		
		var closeButtonImageNormal = this.getBaseResourcePath() + "close-button-normal.png";
		var closeButtonImagePressed = this.getBaseResourcePath() + "close-button-pressed.png";
			
		var genericButtonImagePathNormal = this.getBaseResourcePath() + "button-normal.png";
		var genericButtonImagePathPressed = this.getBaseResourcePath() + "button-pressed.png";
		
		var soundOnButtonImagePathNormal = this.getButtonImagePath() + "sound-on.png";
		var soundOffButtonImagePathPressed = this.getButtonImagePath() + "sound-off.png";	
		
		var effectsOnButtonImagePathNormal = this.getButtonImagePath() + "effects-on.png";
		var effectsOffButtonImagePathPressed = this.getButtonImagePath() + "effects-off.png";
		
		var creditsButtonImagePathNormal = this.getButtonImagePath() + "credits-button-normal.png";
		var creditsButtonImagePathPressed = this.getButtonImagePath() + "credits-button-pressed.png";
		
		var feedbackButtonImagePathNormal = this.getButtonImagePath() + "feedback-normal.png";
		var feedbackButtonImagePathPressed = this.getButtonImagePath() + "feedback-pressed.png";							

		this._backgroundImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(45)], null, backgroundImagePath, [TCUtil.getAdjustedX(320),TCUtil.getAdjustedY(380)]);
		this.addChild(this._backgroundImage);
		
		this._menuTopLabel = GLFactory.getText([TCUtil.getAdjustedX(110), TCUtil.getAdjustedY(30)], 100,Core.Localization.getString("SETTINGS"), [TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], new Core.Color(1,1,1));
		this._backgroundImage.addChild(this._menuTopLabel);
		
		this._closeButton = new GLButton(closeButtonImageNormal, closeButtonImagePressed, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(40), this.onCloseTouch.bind(this), this._backgroundImage, 3, null, null, null, null, null);
		this._closeButton.setPosition(TCUtil.getAdjustedX(280), TCUtil.getAdjustedY(25));
		
		this._sendFeedbackButton = new GLButton(feedbackButtonImagePathNormal, feedbackButtonImagePathPressed, TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50), this.onSendFeedbackTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("SEND_FEEDBACK"), new Core.Color(1,1,1), null, null, TCUtil.getAdjustedFontSize(90));
		this._sendFeedbackButton.setPosition(TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(85));
		this._sendFeedbackButton.setButtonTextBelowButton();
		
		this._creditsButton = new GLButton(creditsButtonImagePathNormal, creditsButtonImagePathPressed, TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50), this.onCreditsTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("CREDITS"), new Core.Color(1,1,1), null, null, TCUtil.getAdjustedFontSize(90));
		this._creditsButton.setPosition(TCUtil.getAdjustedX(163),TCUtil.getAdjustedY(85));
		this._creditsButton.setButtonTextBelowButton();
		
		this._soundButton = new GLButton(soundOnButtonImagePathNormal, soundOffButtonImagePathPressed, TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50), this.onSoundButtonTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("SOUND"), new Core.Color(1,1,1), null, null, TCUtil.getAdjustedFontSize(90));
		this._soundButton.setPosition(TCUtil.getAdjustedX(250),TCUtil.getAdjustedY(85));
		this._soundButton.setButtonTextBelowButton();
		
		this._effectsButton = new GLButton(effectsOnButtonImagePathNormal, effectsOffButtonImagePathPressed, TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50), this.onEffectsButtonTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("EFFECTS"), new Core.Color(1,1,1), null, null, TCUtil.getAdjustedFontSize(90));
		this._effectsButton.setPosition(TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(165));
		this._effectsButton.setButtonTextBelowButton();
		
		this.checkSoundAndEffectsState();
	},  
	
	onSendFeedbackTouch: function() 
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
        if(this._webView)
        {
            NGWindow.document.removeChild(this._webView);
            this._webView.destroy();
            this._webView = null;
        }
		this._webView = new UI.WebView();
        this._webView.setFrame([TCUtil.getAdjustedX(0), TCUtil.getAdjustedY(0), 0, 0]);
		this._webView.setBackgroundColor('00000000');
        var appName = '';
        
        if(( Core.Capabilities.getPlatformOS() == 'Android') )
        {
            appName = MM_APP_NAME;
        }
        else
        {
            appName = MM_IOS_APP_NAME;
        }
        
		var feedbackSubject = appName+' v'+GAConfigurations.getGameVersion()+' - Feedback';
        var userId = GAConfigurations.getUserId();
     	var feedbackBody = '\n\n'+Core.Localization.getString("DO_NOT_CHANGE")+':  DEVICE : '+GAConfigurations.getDeviceName()+' '+GAConfigurations.getDeviceType()+'| IMEI/UDID : '+GAConfigurations.getUdid()+' | UserId : '+userId+' | VERSION : '+MM_VERSION_NUMBER+' | BUILD : '+MM_BUILD_NUMBER+' | GAME : '+GAConfigurations.getGameCode()+' | OS : '+GAConfigurations.getOsVersion();
		var urlString = '?subject='+encodeURI(feedbackSubject)+'&body='+encodeURI(feedbackBody);
		var consolidatedURL = 'mailto:gaminationsdev@gaminations.com,games@cobaltplay.com'+urlString;
		
		this._webView.loadUrl(consolidatedURL);
		NGWindow.document.addChild(this._webView);
	},
	
	onCreditsTouch: function()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		var creditsWindow = new MMCreditsWindow();
		creditsWindow.createView();
		creditsWindow.setDepth(5);
		MMGameLayer.getControlLayer().addChild(creditsWindow);
		this.destroy();
	},
	
	checkSoundAndEffectsState: function()
	{
		var soundOnButtonImagePathNormal = this.getButtonImagePath() + "sound-on.png";
		var soundOffButtonImagePathPressed = this.getButtonImagePath() + "sound-off.png";
		
		var effectsOnButtonImagePathNormal = this.getButtonImagePath() + "effects-on.png";
		var effectsOffButtonImagePathPressed = this.getButtonImagePath() + "effects-off.png";	
			
		var musicOn = MMSoundManager.getMusicState();
		var effectsOn = MMSoundManager.getEffectsState();
		
		if(musicOn == "false")
		{
			this._soundButton._path1 = soundOffButtonImagePathPressed;
			this._soundButton._path2 = soundOnButtonImagePathNormal;
			this._soundButton.getButton().setImage(soundOffButtonImagePathPressed,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);
		}
		if(effectsOn == "false")
		{
			this._effectsButton._path1 = effectsOffButtonImagePathPressed;
			this._effectsButton._path2 = effectsOnButtonImagePathNormal;
			this._effectsButton.getButton().setImage(effectsOffButtonImagePathPressed,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);
		}
	},
	
	onSoundButtonTouch: function()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		var soundOnButtonImagePathNormal = this.getButtonImagePath() + "sound-on.png";
		var soundOffButtonImagePathPressed = this.getButtonImagePath() + "sound-off.png";		
		var musicOn = MMSoundManager.getMusicState();
		if(musicOn == "true")
		{
			MMSoundManager.setMusicState("false");
			MMSoundManager.toggleBackgroundMusic();		
			
			this._soundButton._path1 = soundOffButtonImagePathPressed;
			this._soundButton._path2 = soundOnButtonImagePathNormal;
			this._soundButton.getButton().setImage(soundOffButtonImagePathPressed,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);
		}
		else
		{
			MMSoundManager.setMusicState("true");
			MMSoundManager.toggleBackgroundMusic();			
	
			this._soundButton._path1 = soundOnButtonImagePathNormal;
			this._soundButton._path2 = soundOffButtonImagePathPressed;
			this._soundButton.getButton().setImage(soundOnButtonImagePathNormal,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);			
		}
	},
	
	onEffectsButtonTouch: function()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		var effectsOnButtonImagePathNormal = this.getButtonImagePath() + "effects-on.png";
		var effectsOffButtonImagePathPressed = this.getButtonImagePath() + "effects-off.png";			
			
		var effectsOn = MMSoundManager.getEffectsState();
		if(effectsOn == "true")
		{
			MMSoundManager.toggleEffects();
		
			this._effectsButton._path1 = effectsOffButtonImagePathPressed;
			this._effectsButton._path2 = effectsOnButtonImagePathNormal;
			this._effectsButton.getButton().setImage(effectsOffButtonImagePathPressed,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);
		}
		else
		{
			MMSoundManager.toggleEffects();			
		
			this._effectsButton._path1 = effectsOnButtonImagePathNormal;
			this._effectsButton._path2 = effectsOffButtonImagePathPressed;
			this._effectsButton.getButton().setImage(effectsOnButtonImagePathNormal,[TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(50)]);			
		}		
	},
	
	makeTouchSwallower: function()
    {
    	var width = 0 , height = 0;
    	width = Core.Capabilities.getScreenWidth();
		height = Core.Capabilities.getScreenHeight();
        
    	this._dissolveTouchesTarget = new GL2.TouchTarget();
    	this._dissolveTouchesTarget.setAnchor(0,0);
		this._dissolveTouchesTarget.setSize(TCUtil.getAdjustedX(width),TCUtil.getAdjustedY(height));
        this._dissolveTouchesTarget.setPosition(TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0));
     
        this._myMessageListener = new Core.MessageListener();
		this._dissolveTouchesTarget.getTouchEmitter().addListener(this._myMessageListener, this.dissolveTouches.bind(this),10); //@ make this 10 go to Constants.
		this.addChild(this._dissolveTouchesTarget);
    },
    
    dissolveTouches: function()
    {
    	return true;
    },
	
	
	onCloseTouch: function ()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		this.destroy();
	},
	
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/";
	},
	
	getButtonImagePath: function()
	{
		return "./Content/images/gamelayer/controllayer/menubuttons/";
	},
	
	destroy: function ()
	{
		if(this._backgroundImage)
		{
			this._backgroundImage.destroy();
			this._backgroundImage = null;
		}
		if(this._closeButton)
		{
			this._closeButton.destroy();
			this._closeButton = null;
		}
		if(this._menuTopLabel)
		{
			this._menuTopLabel.destroy();
			this._menuTopLabel = null;
		}
		if(this._dissolveTouchesTarget)
		{
			this._dissolveTouchesTarget.destroy();
			this._dissolveTouchesTarget = null;
		}
		if(this._myMessageListener)
		{
			this._myMessageListener.destroy();
			this._myMessageListener = null;
		}
		if(this._webView)
		{
			this._webView.destroy();
			this._webView = null;
		}
		if(this._sendFeedbackButton)
		{
			this._sendFeedbackButton.destroy();
			this._sendFeedbackButton = null;
		}
		if(this._creditsButton)
		{
			this._creditsButton.destroy();
			this._creditsButton = null;
		}
		if(this._soundButton)
		{
			this._soundButton.destroy();
			this._soundButton = null;
		}
		if(this._effectsButton)
		{
			this._effectsButton.destroy();
			this._effectsButton = null;
		}
	}
});